package com.ruoyi.task;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * @Author alison
 * @Date 2024/11/30 20:30
 * @Version 1.0
 * @Description
 */
//@ComponentScan(basePackageClasses = {SchedBean.class, BootSched.class})
@EnableScheduling
@PropertySource("classpath:application-sched.properties")
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, QuartzAutoConfiguration.class})
@Configuration
@SpringBootTest
public class BootSched {

    public static void main(String[] args) {
        System.setProperty("spring.main.web-application-type", "none");
        System.setProperty("spring.main.allow-bean-definition-overriding", "true");
        SpringApplication.run(BootSched.class, args);
    }

    @Scheduled(cron = "0/2 * * * * ?")
    public void sched() {
        System.out.println("+++++++++++++++++++");
        System.out.println("new Date() = " + new Date());
        System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getName());
        System.out.println("-------------------");
    }

}
